home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
qbnws302.zip
/
LINEDIT.ZIP
/
LINEEDIT.BAS
< prev
next >
Wrap
BASIC Source File
|
1992-03-22
|
18KB
|
417 lines
DEFINT A-Z
'+==================================================================+
'| LINEEDIT.BAS |
'| |
'| A line edit routine developed by Larry Stone and the SWOCC |
'| students of Larry Stone, CS133B, Fall Term '91, SWOCC. |
'| |
'| Purpose: Line editor that can edit a string in a virtual |
'| window, VwindowSize%, bigger than the allowable |
'| display length, DisplayLen% |
'| |
'| Modules: LINEEDIT |
'| KEYBOARD |
'| |
'| Call: LineEdit Row%, Col%, CurPos%, A$, VwindowSize%, _ |
'| DisplayLen%, CuroffSet%, Kee%, Separaters$,_ |
'| Terminators() |
'+------------------------------------------------------------------+
'
'+==================================================================+
'| DECLARATIONS |
'+------------------------------------------------------------------+
'
DECLARE FUNCTION InsertState% ()
DECLARE FUNCTION KeyPressed% ()
DECLARE FUNCTION Lower% (Value%)
DECLARE SUB RingSound ()
DECLARE FUNCTION Upper% (Value%)
CONST False = 0, True = NOT False
'+==================================================================+
'| SUBPROGRAMS |
'+------------------------------------------------------------------+
'+======================================================================+
'| LIneEdit Subprogram |
'| |
'| Developed by: Larry Stone & his students during Fall & Winter term, |
'| 1991-1992, Southwestern Oregon Community College. |
'| |
'| Purpose: Line editor that can scroll/edit a virtual window longer |
'| than the displayable line. |
'| |
'| Input: Row% The Row to display the edit string. |
'| Col% The starting column for the edit string. |
'| VwindowSize% The length of optional virtual window. |
'| If VwindowSize is less than DisplayLen then |
'| it is automatically sized to DisplayLen. |
'| DisplayLen% The length allowed for string display. |
'| Separaters$ String defining word separaters. |
'| AutoTerminate% Boolean statement - If true, terminates |
'| LineEdit when CurPos is at end of field. |
'| Terminators%() Integer Array defining exit key strokes. |
'| Zeroeth element defines last terminator |
'| used. MUST BE DIMMED IN CALLING PROGRAM! |
'| |
'| EditMask$ Optional string of symbols that serve to |
'| mask the corresponding character in the |
'| the edit string (A$). |
'| |
'| # chr(35) digits 0-9 and any uppercase character |
'| A chr(65) uppercase only (converts to upper case) |
'| 9 chr(57) digits 0-9 only |
'| ? chr(63) anything at all |
'| 8 chr(56) digits 0-9, uppercase, "/", or space |
'| * chr(42) any alpha, dash, apostraphe or space |
'| a chr(97) lower case alpha only |
'| |
'| Input/Output: |
'| A$ The string to edit - the edited string. |
'| CurPos% Cursor location within the displayed string |
'| (use value as input to re-edit string). |
'| CurOffset% Adjustment factor for left-most character |
'| of the displayed string (use value as input |
'| to re-edit string). |
'| |
'| Output: Kee% The exit key user hit to exit this routine. |
'| |
'| Note: Extended keys, ie., up/down arrow, are returned as negative |
'| numbers. |
'| |
'| Edit Functions: |
'| Backspace Deletes character to left of cursor |
'| Delete Deletes character under cursor |
'| Ctrl + Home Deletes from cursor to beginning of line |
'| Ctrl + End Deletes from cursor to end of line |
'| Ctrl + Right Move to word on right (skips separaters) |
'| Ctrl + Left Move to word on left (skips separaters) |
'| Home Move to beginning of string |
'| End Move to space after last char of string |
'| Right Move cursor one character to right |
'| Left Move cursor one character to left |
'| |
'+----------------------------------------------------------------------+
'
SUB LineEdit (Row%, Col%, CurPos%, A$, VwindowSize%, DisplayLen%, CurOffset%, Kee%, Separaters$, Terminators(), EditMask$, AutoTerminate%)
IF VwindowSize% < DisplayLen% THEN VwindowSize% = DisplayLen%
IF CurPos = False THEN CurPos = 1 'Set cursor position
Escan = 7 'Set End Scan Line
'---- Insert is either On or Off
InsIsOn% = InsertState%
GOSUB DisplayLine 'Display the string to edit
COLOR 14, False 'Force color change with edits
IF LEN(EditMask$) THEN 'If we have an edit mask...
IF LEN(EditMask$) < VwindowSize% THEN 'and it a wee short...
'---- Pad the edit mask with "?" (anything) symbols
EditMask$ = EditMask$ + STRING$(VwindowSize% - LEN(EditMask$), 63)
END IF
END IF
DO
DO
LastIns = InsIsOn 'Save the state of the Ins key
Kee% = KeyPressed% 'Get a key from keyboard buffer
'---- If Insert is changed then toggle the state of InsIsOn
IF Kee = -82 THEN Kee = False: InsIsOn = InsIsOn XOR True
IF LastIns <> InsIsOn THEN GOSUB SetLocation
'---- Loop to the last terminator used. Is it our keystroke?
FOR N = 1 TO Terminators(False)
IF Terminators(N) = Kee% THEN Terminated = True
NEXT
LOOP UNTIL Kee%
IF Terminated THEN EXIT DO
StrPos = CurPos + CurOffset 'Pointer into the string
CharOK = True 'Initialize this to true
IF LEN(EditMask$) THEN
'---- If Kee isn't an extended keystroke, backspace or enter...
IF NOT (Kee% < False OR Kee = 8 OR